# 一错误方法
class Solution:
    def maxPoints(self, points: List[List[int]]) -> int:
        dic1 = {} # 储存对应斜率和截距
        dic2 = {} # 对应个数
        m = len(points)
        if m <= 2:
            return m 
        for i in range(m):
            for j in range(i + 1, m):
                div = (points[i][0] - points[j][0])
                if div == 0: # 除数为0的情况
                    k = None
                    c = points[i][0]
                else:
                    k = (points[i][1] - points[j][1]) / div
                    c = points[i][1] - k * points[i][0]
                    c = round(c, 4)
                if k in dic1 and dic1[k] == c:
                    dic2[(k, c)] += 1
                else:
                    dic1[k] = c 
                    dic2[(k, c)] = 1
        # print(dic2)
        ans = int((1 + pow((1 + 8 * max(dic2.values())), 0.5)) / 2) # 去除重复的节点
        return ans
# deepseek
class Solution:
    def maxPoints(self, points: List[List[int]]) -> int:
        n = len(points)
        if n <= 2:
            return n
        
        max_count = 0
        for i in range(n):
            slope_count = defaultdict(int)
            duplicate = 1  # 包含自身
            
            for j in range(n):
                if i == j:
                    continue
                
                x1, y1 = points[i]
                x2, y2 = points[j]
                
                # 处理重复点
                if x1 == x2 and y1 == y2:
                    duplicate += 1
                    continue
                
                # 计算分子分母
                dx = x2 - x1
                dy = y2 - y1
                
                # 约分化简分数
                if dx == 0:  # 垂直线
                    slope = (0, 1)
                elif dy == 0:  # 水平线
                    slope = (1, 0)
                else:
                    # 处理符号一致性
                    if dx < 0:
                        dx, dy = -dx, -dy
                    gcd_val = math.gcd(abs(dx), abs(dy))
                    slope = (dx // gcd_val, dy // gcd_val)
                
                slope_count[slope] += 1
            
            # 更新当前基准点的最大共线点数
            current_max = duplicate
            if slope_count:
                current_max += max(slope_count.values())
            
            max_count = max(max_count, current_max)
        
        return max_count
        

# 灵茶山艾府
class Solution:
    def maxPoints(self, points: List[List[int]]) -> int:
        ans = 0
        for i, (x, y) in enumerate(points):
            cnt = defaultdict(int)
            for x2, y2 in points[i + 1:]:
                dx, dy = x2 - x, y2 - y
                k = dy / dx if dx else inf
                cnt[k] += 1
                ans = max(ans, cnt[k])  # 这里没有算上 (x,y) 这个点，最后再加一
        return ans + 1
